import numpy as np
import pandas as pd
from matplotlib import pyplot
from pandas import DataFrame
from sklearn.metrics import mean_squared_error
from statsmodels.tsa.arima.model import ARIMA
import matplotlib.pyplot as plt
import statsmodels.api as sm  # acf,pacf图
from scipy import  stats
from statsmodels.graphics.api import qqplot
import scipy.stats as sct

# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    data = pd.read_excel("data/bitcoin.xlsx", index_col='Date')
    print(data)

    # 定阶结果 p=8,q=7
    X = data.values
    size = int(len(X) * 0.96)
    train, test = X[0:size], X[size:len(X)]
    history = [x for x in train]
    predictions = list()
    for t in range(len(test)):
        model = ARIMA(history, order=(8, 1, 7))
        model_fit = model.fit()
        output = model_fit.forecast()
        yhat = output[0]
        predictions.append(yhat)
        obs = test[t]
        history.append(obs)
        print('predicted=%f, expected=%f' % (yhat, obs))
    error = mean_squared_error(test, predictions)
    print('Test MSE: %.3f' % error)
    # plot
    pyplot.plot(test)
    pyplot.plot(predictions, color='red')
    pyplot.show()